# coding: utf-8
from sqlalchemy import Column, Date, Float, Integer, text, Boolean, String
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()
metadata = Base.metadata

# 股票
class MarketStock(Base):
    __tablename__ = 'stock'
    __table_args__ = {'schema': 'stock_market'}

    code = Column(String(32), primary_key=True)
    sname = Column(String(128), nullable=False)
    exchange = Column(String(128))
    ah = Column(Boolean)
    entry_time = Column(Date)

# ETF
class MarketFunc(Base):
    __tablename__ = 'fund'
    __table_args__ = {'schema': 'stock_market'}

    code = Column(String(32), primary_key=True)
    sname = Column(String(128), nullable=False)
    exchange = Column(String(128))
    ah = Column(Boolean)
    entry_time = Column(Date)

# 单只股票
class StockQfq(Base):
    __tablename__ = 'stock_qfq_default'
    __table_args__ = {'schema': 'stock_datas'}

    id = Column(Integer, primary_key=True, autoincrement=True)
    date = Column(Date, nullable=False, unique=True)
    open = Column(Float, nullable=False)
    close = Column(Float, nullable=False)
    hight = Column(Float, nullable=False)
    low = Column(Float, nullable=False)
    volume = Column(Float(53), server_default=text("0.0"))
    volume_quota = Column(Float(53), server_default=text("0.0"))
    vibration = Column(Float)
    rise_fall_rate = Column(Float, server_default=text("0.0"))
    rise_fall_quota = Column(Float, server_default=text("0.0"))
    turnover_rate = Column(Float)

# 单只ETF
class FundQfq(Base):
    __tablename__ = 'fund_default'
    __table_args__ = {'schema': 'fund'}

    id = Column(Integer, primary_key=True, autoincrement=True)
    date = Column(Date, nullable=False, unique=True)
    open = Column(Float, nullable=False)
    close = Column(Float, nullable=False)
    hight = Column(Float, nullable=False)
    low = Column(Float, nullable=False)
    volume = Column(Float(53), server_default=text("0.0"))
    volume_quota = Column(Float(53), server_default=text("0.0"))
    vibration = Column(Float)
    rise_fall_rate = Column(Float, server_default=text("0.0"))
    rise_fall_quota = Column(Float, server_default=text("0.0"))
    turnover_rate = Column(Float)